import { find, game, Game, instantiate, Label, log, Node, Prefab, resources, SpriteFrame, sys, Toggle } from "cc"
import { ccclass, BaseUI, EUILayer, EBlockOnceAdType, EPlatformType, EBottomAdType, _config_, _privacy, SwitchSpriteCC, _platform, _ui, _guide, _audio, _gameType } from "../../main/script/Main"
import { losChannel } from "../../app/Script/SDK/losChannel"
import losPrivacyWin from "../../app/Script/UI/losPrivacyWin"
import { losTools } from "../../app/Script/Tools/losTools"
import loskc from "../../app/Script/SDK/loskc"
import privacyWin from "../../scripts/ui/privacyWin"


@ccclass("SettingUI")
export class SettingUI extends BaseUI {
	public layerType = EUILayer.Panel
	public blockOnceAdType = EBlockOnceAdType.Show

	private cSwitchChildrenCC_music: SwitchSpriteCC = null!
	private cSwitchChildrenCC_sound: SwitchSpriteCC = null!
	private cSwitchChildrenCC_btn: SwitchSpriteCC = null!
	private cBtns: Node = null!
	private cAUser: Node = null!
	private cADec: Node = null!

	protected onCreate(): void {
		// switch (_platform.type) {
		// 	case EPlatformType.wx:
		// 		this.bottomAdType = EBottomAdType.Native
		// 		break;
		// 	case EPlatformType.vivo:
		// 		this.bottomAdType = EBottomAdType.Native
		// 		break;
		// 	case EPlatformType.oppo:
		// 		this.bottomAdType = EBottomAdType.Native
		// 		break;
		// 	default:
		// 		this.bottomAdType = EBottomAdType.Banner
		// 		break;
		// }
	}

	protected onOpen() {
		this.updateView()
		_guide.closeFinger()

		losChannel.instance().getChannel().doAction("所有二级界面弹出插屏", ['hw'])
		// if (!initData.openPrivacy) {
		// 	this.cAUser.active = false
		// 	this.cADec.active = false
		// }
		// else {
		// this.cAUser.active = false
		// this.cADec.active = false
		const channelName = losChannel.instance().channel;
		// if (channelName == 'vivo' || channelName == 'oppo' || channelName == 'vivo1' || channelName == 'xiaomi' || channelName == 'oppo1') {
		// 	this.cADec.active = true

		// }
		// }


		log("打开设置界面settingUI")
	}
	protected onClose(): void {
		log("关闭设置界面settingUI")
		losChannel.instance().closeBanner()
	}

	private onClickReset() {
		if (_gameType.hasRun()) {
			this.closeUI()
			_gameType.reset()
		}
	}

	private onClickExit() {
		this.closeUI()
		_gameType.settingExit()
		// losChannel.instance().doAction(10, ["vivo", 'oppo'], (enabled, val) => {
		// 	if (enabled) {
		// 		losChannel.instance().showMultiInter(2, { top: losChannel.instance().getSysInfo().windowHeight / 2 - 100 })
		// 	}
		// })
		losChannel.instance().doAction(-1, ['hw']);
		const channelName = losChannel.instance().channel
		if (channelName == 'vivo' || channelName == 'oppo' || channelName == 'xiaomi' || channelName == 'vivo1' || channelName == 'oppo1')
			losTools.showKuangDian(true)
		else if (channelName == 'ks') {

		}
	}

	private onClickAUser() {
		// _privacy.openUserUI()
	}


	// private onClickADec() {
	// 	// _privacy.openDecUI()
	// 	let node = find("UICanvas/privacyWinNode/")
	// 	node.setSiblingIndex(9999)
	// 	let p: losPrivacyWin = node.getComponentInChildren(losPrivacyWin)
	// 	if (p) {
	// 		p.showAsyn(true)
	// 	}
	// }

	private onClickSwitchChildrenCC_music() {
		if (_audio.getVolume(true) == 1)
			_audio.setVolume(true, 0)
		else
			_audio.setVolume(true, 1)
		this.updateView()
	}

	private onClickSwitchChildrenCC_sound() {
		if (_audio.getVolume(false) == 1)
			_audio.setVolume(false, 0)
		else
			_audio.setVolume(false, 1)
		this.updateView()
	}


	private updateView() {
		if (_audio.getVolume(true) == 1)
			this.cSwitchChildrenCC_music.index = 0
		else
			this.cSwitchChildrenCC_music.index = 1

		if (_audio.getVolume(false) == 1)
			this.cSwitchChildrenCC_sound.index = 0
		else
			this.cSwitchChildrenCC_sound.index = 1

	}

	onClickPrivacy() {
		resources.load('privacyWin', Prefab, (error, Prefab) => {
			let node = instantiate(Prefab)

			node.parent = find("UICanvas");
			node.getComponent(privacyWin).showWin2()

		})
	}

}
